package cn.edu.ctbu.zyy.service;


import cn.edu.ctbu.zyy.dao.TeacherRepository;
import cn.edu.ctbu.zyy.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherService {

    @Autowired
    public TeacherRepository teacherRepository;

    /**
     * 读所有的教师列表
     *
     * @return List Teacher
     */
    public List<Teacher> getAll() {

        return teacherRepository.findAll();
    }

    public Teacher findById(int id) {
        return teacherRepository.findById(id).get();
    }

    /**
     * 新增教师
     *
     * @param teacher
     * @return
     */
    public Teacher add(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    /**
     * 更新教师
     *
     * @param teacher
     * @return
     */
    public Teacher update(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    /**
     * 删除教师
     *
     * @param id
     */
    public void delete(Integer id) {
        teacherRepository.deleteById(id);
    }

}
